package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 事务控制
 */
public class JDBCDemo11 {
    public static void main(String[] args) {
        try(Connection conn=DBUtil.getConnection()) {
            conn.setAutoCommit(false);
            PreparedStatement ps=conn.prepareStatement("delete from user where id=?");
            ps.setInt(1,2);
            int num = ps.executeUpdate();
            conn.commit();
//            conn.rollback();
            if(num>0){
                System.out.println("删除成功");
            }else{
                System.out.println("删除失败");
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
